package com.ltu.service.impl.customize;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ltu.domain.mp_entity.customize.DeviceEntity;
import com.ltu.mapper.customize.DeviceMapper;
import com.ltu.service.customize.DeviceService;
import org.springframework.stereotype.Service;
import com.ltu.service.impl.BaseServiceImpl;

/**
 * <p>
 * 设备 服务实现类
 * </p>
 *
 * @author 若尘
 * @since 2024-09-26
 */
@Service
public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, DeviceEntity> implements DeviceService {

	@Override
	public DeviceEntity getByDeviceNo(String deviceMac) {
		QueryWrapper<DeviceEntity>  qw = new QueryWrapper<DeviceEntity>();
		qw.lambda().eq(DeviceEntity :: getDeviceNo, deviceMac)
		.last("limit 1");
		return this.getOne(qw);
	}
	
	/**
	 * 更新设备上下线
	 * @author 李生
	 * @date 2024-10-17 10:10:41 
	 * @param deviceMac
	 * @param onlineFlag 0下线1上线
	 */
	@Override
	public DeviceEntity editOnline(String deviceMac,int onlineFlag) {
		QueryWrapper<DeviceEntity> uw = new QueryWrapper<DeviceEntity>();
			uw.lambda().eq(DeviceEntity :: getDeviceNo, deviceMac);
					
			DeviceEntity target =	this.getOne( uw);
					target.setOnlineState(onlineFlag==1?true:false);
					if(target==null)
						return null;
		 this.updateById(target);
		 return target;
	}

   
}
